import java.util.ArrayList;
import java.util.LinkedList;

public class Main {
    public static void main(String[] args) {
        SingleLinkedList singleLinkedList = new SingleLinkedList();
        singleLinkedList.addFirst(1);
        //singleLinkedList.addLast(5);
        singleLinkedList.display();

        /*System.out.println();
        System.out.println(singleLinkedList.size());

        singleLinkedList.addLast(1);
        singleLinkedList.addFirst(1);
        singleLinkedList.remove(1);
        singleLinkedList.display();

        System.out.println();
        singleLinkedList.removeAllKey(1);
        singleLinkedList.display();

        singleLinkedList.addIndex(0,1);
        singleLinkedList.addIndex(100,100);
        System.out.println();
        singleLinkedList.display();

        System.out.println(singleLinkedList.contains(1));*/

    }
    /*public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();

        System.out.println("Hello world!");
    }

    public boolean chkPalindrom(){
        ListNode slow = Head;
        ListNode fast = Head;
        while(fast != null){
            fast = fast.next.next;
            slow = slow.next;
        }
        ListNode cur = slow;
        slow = slow.next;
        ListNode curn = fast;
        while(cur != curn){
            ListNode temp = slow.next;
            slow.next = cur;
            cur = slow;
            slow = slow.next;
        }
        ListNode h = head;
        while(h != fast){
            if(h.val != fast.val){
                return false;
            }
            h = h.next;
            fast = fast.next
        }
        return true;
    }
    public void display(){
        if(head == null){
            return;
        }
        ListNode cur = head;
        while(cur.next != null){
            System.out.print(cur.val+" ");
            cur = cur.next;
        }
    }
    public int size(){
        if(head == null){
            return 0;
        }
        ListNode cur = head;
        int size = 0;
        while(cur.next != null){
            size++;
        }
        return size;
    }
    public boolean contains (int key){
        if(head == null){
            return false;
        }
        ListNode cur = head;
        while(cur.next != null){
            if(cur.val == key){
                return true;
            }
            cur = cur.next;
        }
        return false;
    }
    public void addIndex(int index, int data) {
        int len = size();
        if(index < 0 || index > len) {
            return;
        }
        if(index == 0) {
            addFirst(data);
            return;
        }
        if(index == len) {
            addLast(data);
            return;
        }
        ListNode cur = head;
        ListNode l = new ListNode(data);
        for (int i = 0; i < index; i++) {
            cur = cur.next;
        }
        l.prev = cur.prev;
        cur.prev.next = l;
        l.next = cur;
        cur.prev = l;
    }*/
}